package org.example;

import com.hjx.http.RequestUtil;
import java.util.HashMap;
import javax.xml.bind.Element;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.junit.Test;

public class UserGroup {

  @Test
  public void test() throws Exception{

    String url = "http://localhost:8081/user_group_manager";
    String result = RequestUtil.post(url, new HashMap<String, String>(){{
      put("name", "user_group_2");
      put("action", "create");
      put("description", "测试用户组二");

    }}, new HashMap<String, String>(){{
      put("Host", "localhost:8081");
      put("Connection", "keep-alive");
      put("Accept", "application/json, text/javascript, */*; q=0.01");
      put("X-Requested-With", "XMLHttpRequest");
      put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
      put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      put("Origin", "http://localhost:8081");
      put("Sec-Fetch-Site", "same-origin");
      put("Sec-Fetch-Mode", "cors");
      put("Sec-Fetch-Dest", "empty");
      put("Referer", "http://localhost:8081/user_group");
      put("Accept-Encoding", "gzip, deflate, br");
      put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
      put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; azkaban.browser.session.id=8fea5d42-a506-4ba1-90d1-7a01022de303; userName=houjinxin; digest=FAE317E5E6CF469E76EE3B817F6358AC; JSESSIONID=node0y83vgwe7k8kk16safynnelcay3.node0");

    }});

    System.out.println(result);

  }

  @Test
  public void test2() throws Exception{

    String url = "http://localhost:8081/user_group";
    String result = RequestUtil.get(url, new HashMap<String, String>(){{

    }}, new HashMap<String, String>(){{
      put("Host", "localhost:8081");
      put("Connection", "keep-alive");
      put("Upgrade-Insecure-Requests", "1");
      put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
      put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
      put("Sec-Fetch-Site", "same-origin");
      put("Sec-Fetch-Mode", "navigate");
      put("Sec-Fetch-User", "?1");
      put("Sec-Fetch-Dest", "document");
      put("Referer", "http://localhost:8081/user_group");
      put("Accept-Encoding", "gzip, deflate, br");
      put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
      put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; azkaban.browser.session.id=4f22463e-e51a-4fb5-adc1-b58a6feb8396; userName=houjinxin; digest=FAE317E5E6CF469E76EE3B817F6358AC; JSESSIONID=node0y83vgwe7k8kk16safynnelcay3.node0");

    }});
//    System.out.println(result);

    Elements eles = Jsoup.parse(result).select("#project-list li");
    eles.forEach(ele -> {
      System.out.println(ele.select("h4 a").text());
    });

//    System.out.println(Jsoup.parse(result).select("#project-list li:nth-child(2) h4 a").text());
  }
}
